package org.ccams.tran;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ccams.domain.TProductplan;
import org.ccams.util.PageParameter;

public class Tran18110 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		int limit = Integer.parseInt(request.getParameter("limit"));
		int start = Integer.parseInt(request.getParameter("start"));
		PageParameter page = new PageParameter();
		page.setLimit(limit);
		page.setStart(start);

		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		ArrayList<TProductplan> al = new ArrayList<TProductplan>();
		int count = getCcamsService().getTproductplanDao().getTproductplanCount();
		List<TProductplan> list = getCcamsService().getTproductplanDao().getTProductplan(page);
		
		for (TProductplan t : list) {
			TProductplan u = new TProductplan();
			
			u.setIdt_productPlan(t.getIdt_productPlan());
			u.setAddress_name(t.getAddress_name());
			u.setClient_name(t.getClient_name());
			u.setStart_date(t.getStart_date());
			u.setKind(t.getKind());
			u.setNumber(t.getNumber());
			u.setLvcai(t.getLvcai());
			u.setBolibaiye(t.getBolibaiye());
			u.setJiaceng(t.getJiaceng());
			u.setProduct(t.getProduct());
			u.setPlan_date(t.getPlan_date());
			u.setTruth_date(t.getTruth_date());
			u.setGuage(t.getGuage());
			u.setGuage_arrive(t.getGuage_arrive());
			u.setRemark(t.getRemark());
			u.setState(t.getState());
			al.add(u);
		}
		JSONArray JsonArray = JSONArray.fromObject(al); // 得到JSON数组
		jsonMap.put("totalProperty", count);
		jsonMap.put("root", JsonArray);
		json.putAll(jsonMap);
	}
}
